#include  "rtos_global.h"
#include  "rtos_classes.h"
#include  "classes.cpp"
#include  "RTX.cpp"
#include  "iprocs.cpp"
#include  "keyboard.cpp"

void process_P(){
    int tWait = 500000;
    env = request_msg_env();

    while (1) {
        get_console_chars (env);
        env = receive_message();
        while (env == NULL) {
            usleep(tWait);
            env = receive_message();
        }
        send_console_chars(env);
        env1 = receive_message();
        while (env == NULL) {
             usleep (tWait);
        env1 = receive_message();
        }
    }
}
int main()
{
 	 //create and enqueue msg envelopes into free envelope queue
 	 //create PCBs, initialize processes(kbd_iproc,crt_iproc)
	 initTable init_table[Num_Proc];
	 init_table [0].pid = KB;
	 init_table [0].priority = NULL;//not in ready queue
	// init_table [0].stack_size = StackSize ;
	 init_table [0].status = I_Process;
	 init_table [0].start_address = (void*)'KB_Process';
	 init_table [1].pid = CRT;
	 init_table [1].priority = NULL;//not in ready queue
	// init_table [1].stack_size = StackSize ;
	 init_table [1].status = I_Process;
	 init_table [1].start_address = (void*)'CRT_Process';
	 init_table [2].pid = ProcessP;
	 init_table [2].priority = 0;//not in ready queue
	 //init_table [2].stack_size = StackSize ;
	 init_table [2].status = Ready;
	 init_table [2].start_address = (void*)'Process_P';
	
         RTX rtx;
         rtx.initialization(init_table);
         

	  process_P();
          getchar();
	  return 0;
}
